package com.test.mchelepesa.activity_fragment_rice.fragment_rice;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebResourceRequest;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.test.mchelepesa.R;
import com.test.mchelepesa.activity_fragment_rice.base_rice.BaseFragment_rice;
import com.test.mchelepesa.bean_rice.StaticConfig_rice;
import com.test.mchelepesa.constant_rice.Constant_rice;

public class DataSafetyFragment_rice extends BaseFragment_rice {

    private WebView webView_rice;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_data_safety_rice, container, false);
        init_rice(view);
        return view;
    }

    @SuppressLint("SetJavaScriptEnabled")
    private void init_rice(View view) {

        initLicense(
                view.findViewById(R.id.fragment_data_safety_view_license),
                view.findViewById(R.id.fragment_data_safety_license_logo),
                view.findViewById(R.id.fragment_data_safety_license_company_name)
        );

        //初始化配置
        webView_rice = view.findViewById(R.id.fragment_data_safety_web_view);
        webView_rice.setInitialScale(100);
        webView_rice.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                return false;
            }

            @Override
            public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
                return shouldOverrideUrlLoading(view, request.getUrl().toString());
            }
        });

        WebSettings settings = webView_rice.getSettings();
        settings.setJavaScriptEnabled(true);
        settings.setTextZoom(100);
        settings.setSupportZoom(true);
        settings.setUseWideViewPort(true);
        settings.setUseWideViewPort(true);
        settings.setDomStorageEnabled(true);
        settings.setBuiltInZoomControls(true);
        settings.setLoadWithOverviewMode(true);
        settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
        settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);

        settings.setAllowUniversalAccessFromFileURLs(true);
        settings.setAllowFileAccessFromFileURLs(true);
        settings.setAllowContentAccess(true);

        switch (StaticConfig_rice.Select_Country) {
            case Constant_rice.Country_Cote://科特
                webView_rice.loadUrl(Constant_rice.Privacy_Cote);
                break;
            case Constant_rice.Country_Tanzania://坦桑
                webView_rice.loadUrl(Constant_rice.Privacy_Tanzania);
                break;
            case Constant_rice.Country_Senegal://塞内
                webView_rice.loadUrl(Constant_rice.Privacy_Senegal);
                break;
            default: webView_rice.loadUrl(Constant_rice.Privacy_Cote);
        }
    }
}